﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] == null || Request.Cookies["pwd"] == null)
            {
                Response.Redirect("WebFrom1.aspx");
            }

            if (Application["chatroom"] == null)
            {
                Application["chatroom"] = new Panel();
            }
            Panel1.Controls.Add((Panel)Application["chatroom"]);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string text = TextBox1.Text;
            string name = (string)Session["name"];
            string time = DateTime.Now.ToString();

            Literal literal = new Literal();
            literal.Text = time + "<br/>" + name + " : "+" "+ text + "<br/>";

            //Panel panel = (Panel)Application["chatRoom"]; pane1.Controls.Add(literal);是下面代码的拆分
            ((Panel)Application["chatRoom"]).Controls.Add(literal);

            TextBox1.Text = null;
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("WebForm1.aspx");
        }
    }
}